<template>
    <a-select show-search placeholder="请选择车型"
     option-filter-prop="children"
      style="width: 100%" 
      :value="getValueSting"
      :filter-option="filterOption" @change="handleChange">
      <a-select-option v-for="t in CarOptions" :key="t.value" :value="t.value">{{t.text}}</a-select-option>
    </a-select>
  </template>
  
  <script>
    import { httpAction,getAction } from '@/api/manage'
    import  filterObj  from '@/utils/util';
    import {initDictOptions} from '@/components/dict/JDictSelectUtil';

    export default {
      name: 'CarSelect',
      props: {
        value: {
          value: [String, Number],
          required: false
        },
        triggerChange:{
          value: Boolean,
          required: false,
          default: true
        },
        type: {
          value: Number,
          required: false,
          default: 0
        },
        disType:{
          value: String,
          required: false,
          default: 'carType'
        }
      },
      data() {
        return {
          CarOptions: {},
        }
      },
      computed: {
        getValueSting(){
          return this.value != null ? this.value : undefined;
        },
      },
      mounted() {
  
      },
      watch: {
        value: {
          immediate: true,
          handler() {
            console.log(this.value);
            this.getCarOptions(this.type);
          }
        },
        disType: {
          immediate: true,
          handler() {
            this.getCarOptions();
          }
        }
      },
      created() {
        
      },
      methods: {
       
        handleChange(val) {
          if(this.triggerChange){
            this.$emit('change', val);
          }else{
            this.$emit('input', val);
          }
        },
        getCarOptions(type) {
          initDictOptions(this.disType).then((res) => {
            if (res.success) {
              this.CarOptions = res.result;
            }
          })
        //   getAction("/crm/product/getproductId",param)
        //     .then((res) => {
        //       if (res.success) {
        //         this.ProductIdOptions = res.result;
        //       } else {
        //         that.$message.warning(res.message)
        //       }
        //     })
        },
        filterOption(input, option) {
          return (
            option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
          );
        },
      },
      model: {
        prop: 'value',
      },
    }
  </script>
  
  <style>
  </style>
  